<?php
function com_upload($a,$name) {
    // dump($name);exit();
    $upload = new \Think\Upload();
     // 实例化上传类
    $upload->maxSize = 3145728;
     // 设置附件上传大小
    $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
     // 设置附件上传类型
    $upload->rootPath = './Public/';
     // 设置附件上传根目录
    if($a=="1"){
        $upload->savePath  =      '/Uploads/Company/';
    }
    elseif ($a=="2") {
          $upload->savePath  =      '/Uploads/Shop/';

    }
    elseif ($a=="3") {
          $upload->savePath  =      '/Uploads/Goods/';

    }
    else{
        $upload->savePath  =      '/Uploads/Other/';
    }
    $upload->autoSub = true;
    $upload->subName ="$name";
     // 设置附件上传（子）目录
    $info = $upload->upload();
    if (!$info) {
         // 上传错误提示错误信息
        // $this->error($upload->getError());
    }
    else {
         // 上传成功
        //$this->success('上传成功！');
        foreach ($info as $key =>$file) {
            $url[$key] = $file['savepath'] . $file['savename'];
        }
        //dump($url);exit();
        return $url;
    }

}

function returngoods($atod,$atsid,$sum){
    ini_set('soap.wsdl_cache_enabled','0');//关闭缓存
    $client=new \SoapClient('http://117.25.129.4:96/services/sms?wsdl');

    $arr = array(
            'in0'=>$atod,
            'in1'=>$atsid,
            'in2'=>$sum,
            'in3'=>md5($atod.$atsid.'CBS275021598872'.$sum),
        );

        $data = $client->returnGoods($arr)->out;

        return $data;

  }

  // 建组
function set_group($group_id){
    $appSec=C('INFO_APP_SEC');
    $nonce = mt_rand();
    $timeStamp = time();
    $signature = sha1($appSec.$nonce.$timeStamp);    //$appSec是平台分配
    $url = 'https://api.cn.ronghub.com/group/create.json';
    $postData ='userId=yyx001&groupId='.$group_id;
    $httpHeader = array(
    'App-Key:'.C('INFO_APP_KEY'),   //平台分配
    'Nonce:'.$nonce,        //随机数
    'Timestamp:'.$timeStamp,    //时间戳
    'Signature:'.$signature,         //签名
    'Content-Type: application/x-www-form-urlencoded',
    );
    $ch = curl_init();
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeader);
    curl_setopt($ch, CURLOPT_TIMEOUT, 30);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
    $result = curl_exec($ch);
    $ant_data=json_decode($result,true);
    curl_close($ch);
    return $ant_data["code"];
}
function getCateType($status){
    if ($status == 1) {
        return '填写';
    }
    if ($status == 2) {
        return '选择';
    }
}
//获得传入时间距离现在的间隔
function getIntervalTime($add_time){
    if ($add_time == 0) {
        return "数据为空";
    }
    $interval = time() - $add_time;
    if ($interval < 60) {
        return "1分钟前";
    }elseif ($interval < 3600) {  //一个小时以内
        return intval($interval/60)."分钟前";
    }elseif ($interval < 24*3600) {  // 一天以内
        return intval($interval/(3600))."小时前";
    }elseif ($interval < (30*24*3600)) { //一个月以内
        return intval($interval/(24*3600))."天前";
    }elseif($interval < (365*24*3600)){
        return intval($interval/(30*24*3600))."月前";
    }else{
        return intval($interval/(365*24*3600))."年前";
    }
}






?>
